package com.qf.j2112.controller;

import com.qf.j2112.anno.JWTAnno;
import com.qf.j2112.po.SysLog;
import com.qf.j2112.po.TourArea;
import com.qf.j2112.service.SysLogService;
import com.qf.j2112.utils.GoodItemsUtil;
import com.qf.j2112.utils.PageUtil;
import com.qf.j2112.vo.ActionResultVO;
import com.qf.j2112.vo.ClientActionResultVo;
import com.qf.j2112.vo.GoodsItemsVo;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class SysLogController {

    @Resource
    private SysLogService sysLogService;

    //后台获取所有日志
    @JWTAnno(name = "获取所有系统日志")
    @GetMapping ("/logs")
    public ActionResultVO getAllLog(PageUtil pageUtil){
        ActionResultVO vo=null;
        List<SysLog> logList=sysLogService.findAllSysLog(pageUtil);
        int num=sysLogService.countLog();
        if (!ObjectUtils.isEmpty(logList)){
            vo=new ActionResultVO(200,"查询可用景区成功",logList,num);
        }else {
            vo=new ActionResultVO(-200,"查询可用景区失败",null);
        }
        return vo;
    }

    //删除一条日志
    @JWTAnno(name = "删除一条日志")
    @DeleteMapping ("/delLog")
    public ActionResultVO delLog(int logId){
        ActionResultVO vo=null;
        if (sysLogService.delOneLog(logId)){
            vo=new ActionResultVO(200,"删除日志成功",null);
        }else {
            vo=new ActionResultVO(-200,"删除日志失败",null);
        }
        return vo;
    }

}
